<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 5.1.6 or newer
 *
 * @package		CodeIgniter
 * @author		ExpressionEngine Dev Team
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc.
 * @license		http://codeigniter.com/user_guide/license.html
 * @link		http://codeigniter.com
 * @since		Version 1.0
 * @filesource
 */
// ------------------------------------------------------------------------

/**
 * CodeIgniter Header Helpers
 *
 * @package		CodeIgniter
 * @subpackage	Helpers
 * @category	Helpers
 * @author		Ricardo Oliveira
 * @link		http://studioprogramar.com.br
 */
// ------------------------------------------------------------------------

/**
 * msgemail
 *
 * Retorna o período atual do aluno.
 * recebe um array contendo os dados do requerimento e uma string contendo o codigo do usuario.
 *
 * @access	public
 * @param	array, string
 * @return	string
 */
if (!function_exists('msgemail')) {

    function msgemail($assunto, $body, $destino, $altBody = '') {
        $ci = & get_instance();
        $ci->load->library('email');
        $config['protocol'] = "smtp";
        $config['smtp_host'] = "ssl://smtp.gmail.com";
        $config['smtp_port'] = "465";
        $config['smtp_user'] = "contato@studioprogramar.com.br";
        $config['smtp_pass'] = "oliver2612";
        $config['charset'] = "utf-8";
        $config['mailtype'] = "html";
        $config['newline'] = "\r\n";
        $ci->email->initialize($config);
        $ci->email->from('contato@studioprogramar.com.br', 'SONIC - Comunicação');
        $ci->email->to([$destino]);
        $ci->email->subject($assunto);
        $ci->email->message($body);
        if ($ci->email->send()) {
            return ['message' => "Mensagem enviada com sucesso! Metodo 1", 'send' => TRUE];
        } else {
            return msgemailAlt($assunto, $body, $destino, $altBody);
        }
    }

}
if (!function_exists('msgemailAlt')) {

    function msgemailAlt($assunto, $body, $destino, $altBody) {
        $ci = & get_instance();
        $ci->load->library("My_PHPMailer");
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        $mail->Host = "ssl://smtp.gmail.com";
        $mail->Port = 465;
        $mail->Username = "contato@studioprogramar.com.br";
        $mail->CharSet = 'utf-8';
        $mail->Password = "oliver2612";
        $mail->SetFrom('contato@studioprogramar.com.br', 'SONIC - Comunicação');
        $mail->IsHTML(true);
        $mail->Subject = $assunto;
        $mail->Body = $body;
        $mail->AltBody = $altBody;
        $mail->AddAddress($destino, "Usuário SONIC");
        return (!$mail->Send()) ?
                ['message' => 'ocorreu um erro durante o envio: ' . $mail->ErrorInfo, 'send' => FALSE] :
                ['message' => "Mensagem enviada com sucesso! Metodo 2", 'send' => TRUE];
    }

}

if (!function_exists('mailTmpl')) {

    function mailTmpl($mailVars, $tmplMail) {
        $template = file_get_contents('./public_html/tmpl/' . $tmplMail . '.html');
        foreach ($mailVars as $key => $value) {
            $template = str_replace('{{ ' . $key . ' }}', $value, $template);
        }
        return $template;
    }

}

// ------------------------------------------------------------------------
/* End of file myemail_helper.php */
/* Location: ./application/helpers/myemail_helper.php */